from django import forms

class RegisterForms(forms.Form):
    username = forms.CharField(min_length=5,max_length=15,
                               error_messages={
                                   "min_length":"用户名太短",
                                   "max_length":"用户名太长",
                                   "required":"用户名不允许为空"
                               })

    password = forms.CharField(min_length=6, max_length=20,
                               error_messages={
                                   "min_length": "密码名太短",
                                   "max_length": "密码名太长",
                                   "required": "密码不允许为空"
                               })

    password2 = forms.CharField(min_length=6, max_length=20,
                               error_messages={
                                   "min_length": "用户名太短",
                                   "max_length": "用户名太长",
                                   "required": "用户名不允许为空"
                               })

    mobile = forms.CharField(min_length=11, max_length=11,
                                error_messages={
                                    "min_length": "手机号不合法",
                                    "max_length": "手机号不合法",
                                    "required": "手机号不允许为空"
                                })

    sms_code = forms.CharField(max_length=4 , min_length=4)
    
    
    def clean(self):
        clean_data = super(RegisterForms, self).clean()
        pw = clean_data.get('password')
        pw2 = clean_data.get('password2')
        if pw != pw2:
            raise forms.ValidationError

        return clean_data



class LoginForms(forms.Form):
    username = forms.CharField(min_length=5, max_length=15,
                               error_messages={
                                   "min_length": "用户名太短",
                                   "max_length": "用户名太长",
                                   "required": "用户名不允许为空"
                               })

    password = forms.CharField(min_length=6, max_length=20,
                               error_messages={
                                   "min_length": "密码名太短",
                                   "max_length": "密码名太长",
                                   "required": "密码不允许为空"
                               })

    remembered = forms.BooleanField(required=False)
